import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_module/common/extensions/cached_network_image_extension.dart';

/// 合作服务商logo编辑组件

class ServiceProviderEditLogo extends StatefulWidget {
  final String? logoUrl;
  final void Function()? onTap;

  const ServiceProviderEditLogo({Key? key, this.logoUrl, this.onTap})
      : super(key: key);

  @override
  ServiceProviderEditLogoState createState() =>
      ServiceProviderEditLogoState(this.logoUrl);
}

class ServiceProviderEditLogoState extends State<ServiceProviderEditLogo> {
  ServiceProviderEditLogoState(String? logoUrl)
      : _logoVN = ValueNotifier(logoUrl);
  final ValueNotifier<String?> _logoVN;
  set logoUrl(String? value) {
    _logoVN.value = value;
  }

  @override
  Widget build(BuildContext context) {
    print('ServiceProviderEditLogoState.build');
    return GestureDetector(
      onTap: widget.onTap,
      child: Container(
        color: CupertinoColors.white,
        padding: EdgeInsets.symmetric(vertical: 10.0, horizontal: 16.0),
        width: double.infinity,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Text(
              '合作服务商logo替换',
              style: TextStyle(
                color: Color(0xff333333),
                fontSize: 12,
                fontWeight: FontWeight.normal,
              ),
            ),
            Row(
              children: [
                Container(
                  decoration: BoxDecoration(
                    border: Border.all(color: Color(0xffe5e5e5)),
                    borderRadius: BorderRadius.circular(5),
                  ),
                  width: 70,
                  height: 70,
                  child: ClipRRect(
                    borderRadius: BorderRadius.circular(5),
                    child: ValueListenableBuilder<String?>(
                      valueListenable: _logoVN,
                      builder: (context, value, child) {
                        return YFNetworkImage(
                          resource: value,
                        );
                      },
                    ),
                  ),
                ),
                SizedBox(
                  width: 20,
                ),
                Icon(
                  Icons.arrow_forward_ios,
                  color: Color(0xff888888),
                  size: 10,
                ),
              ],
            )
          ],
        ),
      ),
    );
  }
}
